///
/// 车贷管理帮助类
///
class LoanUtils {
  static String getResultText(var result) {
    return (result == 1) ? "通过" : "驳回";
  }

  static String getText(var value) {
    return (value != null) ? value.toString() : "";
  }

  static String getYesNo(int value) {
    return (value == 1) ? "是" : "否";
  }

  static String getSexName(int sex) {
    return (sex == 0) ? "男" : "女";
  }

  static String getIdTypeName(int idType) {
    return (idType == 0) ? "身份证" : "居住证";
  }

  static String getFindingName(int value) {
    switch (value) {
      case 1:
        return "正常";
      case 2:
        return "关注";
      default:
        return "拒贷";
    }
  }

  static String getExtTypeName(int extType) {
    return (extType == 0) ? "GPS" : "综合代理费";
  }

  ///
  /// 将数值金额转换为中文大写金额
  ///
  static String toChineseMoneyText(double value) {
    final List<String> cnUpperNumber = [
      "零",
      "壹",
      "贰",
      "叁",
      "肆",
      "伍",
      "陆",
      "柒",
      "捌",
      "玖"
    ];
    final List<String> cnUpperMonetrayUnit = [
      "分",
      "角",
      "圆",
      "拾",
      "佰",
      "仟",
      "万",
      "拾",
      "佰",
      "仟",
      "亿",
      "拾",
      "佰",
      "仟",
      "兆",
      "拾",
      "佰",
      "仟"
    ];
    final String cnFull = "整";
    final String cnNegative = "负";
    final String cnZeroFull = "零圆" + cnFull;
    double sign = value.sign;
    if (sign == value) {
      return cnZeroFull;
    }
    if (value.toStringAsFixed(0).length > 15) {
      return '超出最大限额';
    }
    value = value * 100;
    int tempValue = int.parse(value.toStringAsFixed(0)).abs();

    int p = 10;
    int i = -1;
    String result = '';
    bool lastZero = false;
    bool finish = false;
    bool tag = false;
    bool tag2 = false;
    while (!finish) {
      if (tempValue == 0) {
        break;
      }
      int positionNum = tempValue % p;
      double n = (tempValue - positionNum) / 10;
      tempValue = int.parse(n.toStringAsFixed(0));
      String tempChinese = '';
      i++;
      if (positionNum == 0) {
        if (cnUpperMonetrayUnit[i] == "万" ||
            cnUpperMonetrayUnit[i] == "亿" ||
            cnUpperMonetrayUnit[i] == "兆" ||
            cnUpperMonetrayUnit[i] == "圆") {
          if (lastZero && tag2) {
            result = cnUpperNumber[0] + result;
          }
          result = cnUpperMonetrayUnit[i] + result;
          lastZero = false;
          tag = true;
          continue;
        }
        if (!lastZero) {
          lastZero = true;
        } else {
          continue;
        }
      } else {
        if (lastZero && !tag && tag2) {
          result = cnUpperNumber[0] + result;
        }
        tag = false;
        tag2 = true;
        lastZero = false;
        tempChinese = cnUpperNumber[positionNum] + cnUpperMonetrayUnit[i];
      }
      result = tempChinese + result;
    }
    if (sign < 0) {
      result = cnNegative + result;
    }
    return result;
  }
}
